<template>
  <div class="party-overview">
    <div class="page-header">
      <h1>党建总览</h1>
      <div>
        <el-button type="primary" :loading="loading[active]" @click="refresh">刷新</el-button>
      </div>
    </div>

    <el-tabs v-model="active" class="tabs">
      <el-tab-pane label="组织生活" name="activities">
        <el-card class="filter-card">
          <div class="filters">
            <el-select v-model="qa.type" placeholder="活动类型" clearable style="width: 160px;">
              <el-option label="三会一课" value="三会一课" />
              <el-option label="主题党日" value="主题党日" />
              <el-option label="组织生活会" value="组织生活会" />
              <el-option label="民主评议党员" value="民主评议党员" />
              <el-option label="其他" value="其他" />
            </el-select>
            <el-date-picker v-model="qa.range" type="daterange" range-separator="至" start-placeholder="开始" end-placeholder="结束" value-format="YYYY-MM-DD" style="margin-left:12px;" />
            <el-button type="primary" :loading="loading.activities" style="margin-left:12px;" @click="loadActivities">查询</el-button>
          </div>
        </el-card>

        <el-row :gutter="12" class="stats-row">
          <el-col :span="6"><el-card class="stat"><div>总数</div><div class="num">{{ stats.activities.total }}</div></el-card></el-col>
          <el-col :span="6"><el-card class="stat"><div>待审核</div><div class="num info">{{ stats.activities.pending }}</div></el-card></el-col>
          <el-col :span="6"><el-card class="stat"><div>已驳回</div><div class="num danger">{{ stats.activities.rejected }}</div></el-card></el-col>
          <el-col :span="6"><el-card class="stat"><div>已通过</div><div class="num success">{{ stats.activities.approved }}</div></el-card></el-col>
        </el-row>

        <el-card>
          <el-table :data="activities" stripe v-loading="loading.activities">
            <el-table-column prop="activityDate" label="日期" width="120" />
            <el-table-column prop="activityType" label="类型" width="120" />
            <el-table-column prop="activitySubject" label="主题" min-width="240" show-overflow-tooltip />
            <el-table-column prop="status" label="状态" width="110">
              <template #default="{ row }">
                <el-tag :type="statusTagType(row.status)">{{ statusText(row.status) }}</el-tag>
              </template>
            </el-table-column>
            <el-table-column label="操作" width="260" fixed="right">
              <template #default="{ row }">
                <el-button type="text" @click="viewActivity(row)">查看</el-button>
                <el-button type="text" @click="editActivity(row)">编辑</el-button>
                <el-button type="text" :disabled="row.status!=='PENDING'" @click="openReview('activity', row)">审核</el-button>
                <el-button type="text" style="color:#f56c6c;" @click="removeActivity(row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-card>
      </el-tab-pane>

      <el-tab-pane label="理论学习" name="theory">
        <el-card class="filter-card">
          <div class="filters">
            <el-date-picker v-model="qt.range" type="daterange" range-separator="至" start-placeholder="开始" end-placeholder="结束" value-format="YYYY-MM-DD" />
            <el-button type="primary" :loading="loading.theory" style="margin-left:12px;" @click="loadStudies">查询</el-button>
          </div>
        </el-card>

        <el-row :gutter="12" class="stats-row">
          <el-col :span="6"><el-card class="stat"><div>总数</div><div class="num">{{ stats.theory.total }}</div></el-card></el-col>
          <el-col :span="6"><el-card class="stat"><div>待审核</div><div class="num info">{{ stats.theory.pending }}</div></el-card></el-col>
          <el-col :span="6"><el-card class="stat"><div>已驳回</div><div class="num danger">{{ stats.theory.rejected }}</div></el-card></el-col>
          <el-col :span="6"><el-card class="stat"><div>已通过</div><div class="num success">{{ stats.theory.approved }}</div></el-card></el-col>
        </el-row>

        <el-card>
          <el-table :data="studies" stripe v-loading="loading.theory">
            <el-table-column prop="studyDate" label="日期" width="120" />
            <el-table-column prop="studyTopic" label="主题" min-width="240" show-overflow-tooltip />
            <el-table-column prop="studyForm" label="形式" width="120" />
            <el-table-column prop="studyHours" label="学时" width="100" />
            <el-table-column prop="status" label="状态" width="110">
              <template #default="{ row }">
                <el-tag :type="statusTagType(row.status)">{{ statusText(row.status) }}</el-tag>
              </template>
            </el-table-column>
            <el-table-column label="操作" width="260" fixed="right">
              <template #default="{ row }">
                <el-button type="text" @click="viewStudy(row)">查看</el-button>
                <el-button type="text" @click="editStudy(row)">编辑</el-button>
                <el-button type="text" :disabled="row.status!=='PENDING'" @click="openReview('study', row)">审核</el-button>
                <el-button type="text" style="color:#f56c6c;" @click="removeStudy(row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-card>
      </el-tab-pane>

      <el-tab-pane label="志愿服务" name="volunteer">
        <el-card class="filter-card">
          <div class="filters">
            <el-date-picker v-model="qv.range" type="daterange" range-separator="至" start-placeholder="开始" end-placeholder="结束" value-format="YYYY-MM-DD" />
            <el-button type="primary" :loading="loading.volunteer" style="margin-left:12px;" @click="loadVolunteers">查询</el-button>
          </div>
        </el-card>

        <el-row :gutter="12" class="stats-row">
          <el-col :span="6"><el-card class="stat"><div>总数</div><div class="num">{{ stats.volunteer.total }}</div></el-card></el-col>
          <el-col :span="6"><el-card class="stat"><div>待审核</div><div class="num info">{{ stats.volunteer.pending }}</div></el-card></el-col>
          <el-col :span="6"><el-card class="stat"><div>已驳回</div><div class="num danger">{{ stats.volunteer.rejected }}</div></el-card></el-col>
          <el-col :span="6"><el-card class="stat"><div>已通过</div><div class="num success">{{ stats.volunteer.approved }}</div></el-card></el-col>
        </el-row>

        <el-card>
          <el-table :data="volunteers" stripe v-loading="loading.volunteer">
            <el-table-column prop="serviceDate" label="日期" width="120" />
            <el-table-column prop="serviceTitle" label="主题" min-width="240" show-overflow-tooltip />
            <el-table-column prop="serviceType" label="类型" width="140" />
            <el-table-column prop="serviceHours" label="时长(h)" width="110" />
            <el-table-column prop="status" label="状态" width="110">
              <template #default="{ row }">
                <el-tag :type="statusTagType(row.status)">{{ statusText(row.status) }}</el-tag>
              </template>
            </el-table-column>
            <el-table-column label="操作" width="260" fixed="right">
              <template #default="{ row }">
                <el-button type="text" @click="viewVolunteer(row)">查看</el-button>
                <el-button type="text" @click="editVolunteer(row)">编辑</el-button>
                <el-button type="text" :disabled="row.status!=='PENDING'" @click="openReview('volunteer', row)">审核</el-button>
                <el-button type="text" style="color:#f56c6c;" @click="removeVolunteer(row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-card>
      </el-tab-pane>
    </el-tabs>

    <!-- 审核对话框 -->
    <el-dialog v-model="showReviewDialog" title="审核" width="520px">
      <el-form :model="reviewForm" label-width="96px">
        <el-form-item label="审核结果" required>
          <el-radio-group v-model="reviewForm.status">
            <el-radio label="APPROVED">通过</el-radio>
            <el-radio label="REJECTED">驳回</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="审核意见">
          <el-input v-model="reviewForm.opinion" type="textarea" :rows="4" maxlength="1000" show-word-limit />
        </el-form-item>
      </el-form>
      <template #footer>
        <el-button @click="showReviewDialog=false">取消</el-button>
        <el-button type="primary" :loading="reviewLoading" @click="submitReview">提交</el-button>
      </template>
    </el-dialog>
    
    <!-- 编辑对话框：组织生活 -->
    <el-dialog v-model="showActivityEdit" :title="activityEditForm.id ? '编辑组织生活' : '新增组织生活'" width="720px">
      <el-form :model="activityEditForm" label-width="100px">
        <el-form-item label="活动类型">
          <el-select v-model="activityEditForm.activityType" style="width: 100%">
            <el-option label="三会一课" value="三会一课" />
            <el-option label="主题党日" value="主题党日" />
            <el-option label="组织生活会" value="组织生活会" />
            <el-option label="民主评议党员" value="民主评议党员" />
            <el-option label="其他" value="其他" />
          </el-select>
        </el-form-item>
        <el-form-item label="活动主题"><el-input v-model="activityEditForm.activitySubject" /></el-form-item>
        <el-form-item label="地点"><el-input v-model="activityEditForm.location" /></el-form-item>
        <el-form-item label="主持人"><el-input v-model="activityEditForm.hostName" /></el-form-item>
        <el-form-item label="日期"><el-date-picker v-model="activityEditForm.activityDate" type="date" value-format="YYYY-MM-DD" style="width: 100%" /></el-form-item>
        <el-form-item label="参与人数"><el-input-number v-model="activityEditForm.participantCount" :min="0" :max="9999" /></el-form-item>
        <el-form-item label="缺席"><el-input v-model="activityEditForm.absenceNotes" type="textarea" :rows="2" /></el-form-item>
        <el-form-item label="活动记录"><el-input v-model="activityEditForm.activityRecord" type="textarea" :rows="6" /></el-form-item>
      </el-form>
      <template #footer>
        <el-button @click="showActivityEdit=false">取消</el-button>
        <el-button type="primary" :loading="saving.activity" @click="submitActivityEdit">保存</el-button>
      </template>
    </el-dialog>

    <!-- 详情对话框：理论学习 -->
    <el-dialog v-model="showStudyDetail" title="理论学习详情" width="640px">
      <div v-if="currentStudy">
        <el-descriptions :column="2" border>
          <el-descriptions-item label="学习日期">{{ d(currentStudy.studyDate) }}</el-descriptions-item>
          <el-descriptions-item label="学习形式">{{ currentStudy.studyForm }}</el-descriptions-item>
          <el-descriptions-item label="学习主题" :span="2">{{ currentStudy.studyTopic }}</el-descriptions-item>
          <el-descriptions-item label="学习时长">{{ currentStudy.studyHours ?? '-' }}</el-descriptions-item>
          <el-descriptions-item label="状态">{{ statusText(currentStudy.status) }}</el-descriptions-item>
          <el-descriptions-item label="心得体会" :span="2">{{ currentStudy.notes || '-' }}</el-descriptions-item>
        </el-descriptions>
      </div>
      <template #footer>
        <el-button type="primary" @click="showStudyDetail=false">关闭</el-button>
      </template>
    </el-dialog>

    <!-- 编辑对话框：理论学习 -->
    <el-dialog v-model="showStudyEdit" :title="studyEditForm.id ? '编辑学习记录' : '新增学习记录'" width="640px">
      <el-form :model="studyEditForm" label-width="100px">
        <el-form-item label="学习主题"><el-input v-model="studyEditForm.studyTopic" /></el-form-item>
        <el-form-item label="学习形式">
          <el-select v-model="studyEditForm.studyForm" style="width:100%">
            <el-option label="集中学习" value="集中学习" />
            <el-option label="自学" value="自学" />
            <el-option label="线上学习" value="线上学习" />
            <el-option label="其他" value="其他" />
          </el-select>
        </el-form-item>
        <el-form-item label="学习日期"><el-date-picker v-model="studyEditForm.studyDate" type="date" value-format="YYYY-MM-DD" style="width:100%" /></el-form-item>
        <el-form-item label="学习时长"><el-input-number v-model="studyEditForm.studyHours" :min="0" :max="999" :step="0.5" /></el-form-item>
        <el-form-item label="心得体会"><el-input v-model="studyEditForm.notes" type="textarea" :rows="4" /></el-form-item>
      </el-form>
      <template #footer>
        <el-button @click="showStudyEdit=false">取消</el-button>
        <el-button type="primary" :loading="saving.study" @click="submitStudyEdit">保存</el-button>
      </template>
    </el-dialog>

    <!-- 详情对话框：组织生活 -->
    <el-dialog v-model="showActivityDetail" title="组织生活详情" width="760px">
      <div v-if="currentActivity">
        <el-descriptions :column="2" border>
          <el-descriptions-item label="日期">{{ d(currentActivity.activityDate) }}</el-descriptions-item>
          <el-descriptions-item label="类型">{{ currentActivity.activityType }}</el-descriptions-item>
          <el-descriptions-item label="主题" :span="2">{{ currentActivity.activitySubject }}</el-descriptions-item>
          <el-descriptions-item label="地点">{{ currentActivity.location || '-' }}</el-descriptions-item>
          <el-descriptions-item label="主持人">{{ currentActivity.hostName || '-' }}</el-descriptions-item>
          <el-descriptions-item label="参与人数">{{ currentActivity.participantCount || '-' }}</el-descriptions-item>
          <el-descriptions-item label="缺席">{{ currentActivity.absenceNotes || '-' }}</el-descriptions-item>
          <el-descriptions-item label="状态">{{ statusText(currentActivity.status) }}</el-descriptions-item>
        </el-descriptions>
        <el-divider content-position="left">附件</el-divider>
        <el-table :data="activityAttachments" size="small" stripe>
          <el-table-column prop="fileName" label="文件名" min-width="260" />
          <el-table-column prop="fileUrl" label="链接" min-width="300">
            <template #default="{ row }"><a class="el-link el-link--primary" :href="row.fileUrl" target="_blank">打开</a></template>
          </el-table-column>
        </el-table>
      </div>
      <template #footer>
        <el-button type="primary" @click="showActivityDetail=false">关闭</el-button>
      </template>
    </el-dialog>

    <!-- 详情对话框：志愿服务 -->
    <el-dialog v-model="showVolunteerDetail" title="志愿服务详情" width="640px">
      <div v-if="currentVolunteer">
        <el-descriptions :column="2" border>
          <el-descriptions-item label="服务日期">{{ d(currentVolunteer.serviceDate) }}</el-descriptions-item>
          <el-descriptions-item label="服务类型">{{ currentVolunteer.serviceType || '-' }}</el-descriptions-item>
          <el-descriptions-item label="活动名称" :span="2">{{ currentVolunteer.serviceTitle }}</el-descriptions-item>
          <el-descriptions-item label="服务地点">{{ currentVolunteer.location || '-' }}</el-descriptions-item>
          <el-descriptions-item label="服务时长">{{ currentVolunteer.serviceHours ?? '-' }}</el-descriptions-item>
          <el-descriptions-item label="状态">{{ statusText(currentVolunteer.status) }}</el-descriptions-item>
          <el-descriptions-item label="内容" :span="2">{{ currentVolunteer.description || '-' }}</el-descriptions-item>
        </el-descriptions>
      </div>
      <template #footer>
        <el-button type="primary" @click="showVolunteerDetail=false">关闭</el-button>
      </template>
    </el-dialog>

    <!-- 编辑对话框：志愿服务 -->
    <el-dialog v-model="showVolunteerEdit" :title="volunteerEditForm.id ? '编辑志愿服务' : '新增志愿服务'" width="640px">
      <el-form :model="volunteerEditForm" label-width="100px">
        <el-form-item label="活动名称"><el-input v-model="volunteerEditForm.serviceTitle" /></el-form-item>
        <el-form-item label="服务类型"><el-input v-model="volunteerEditForm.serviceType" placeholder="如 志愿服务/社会实践" /></el-form-item>
        <el-form-item label="服务日期"><el-date-picker v-model="volunteerEditForm.serviceDate" type="date" value-format="YYYY-MM-DD" style="width:100%" /></el-form-item>
        <el-form-item label="服务时长"><el-input-number v-model="volunteerEditForm.serviceHours" :min="0" :max="999" :step="0.5" /></el-form-item>
        <el-form-item label="服务地点"><el-input v-model="volunteerEditForm.location" /></el-form-item>
        <el-form-item label="服务内容"><el-input v-model="volunteerEditForm.description" type="textarea" :rows="4" /></el-form-item>
      </el-form>
      <template #footer>
        <el-button @click="showVolunteerEdit=false">取消</el-button>
        <el-button type="primary" :loading="saving.volunteer" @click="submitVolunteerEdit">保存</el-button>
      </template>
    </el-dialog>
  </div>
</template>

<script setup>
import { ref, reactive, onMounted } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { listActivities, getActivity, updateActivity, deleteActivity, reviewActivity } from '@/api/party'
import { getAllStudies, updateStudy, deleteStudy, reviewStudy } from '@/api/theory'
import { getAllVolunteers, updateVolunteer, deleteVolunteer, reviewVolunteer } from '@/api/volunteer'

const active = ref('activities')
const loading = reactive({ activities: false, theory: false, volunteer: false })
const stats = reactive({ activities: { total: 0, pending: 0, rejected: 0, approved: 0 }, theory: { total: 0, pending: 0, rejected: 0, approved: 0 }, volunteer: { total: 0, pending: 0, rejected: 0, approved: 0 } })

// 数据
const activities = ref([])
const studies = ref([])
const volunteers = ref([])

// 查询条件
const qa = reactive({ type: '', range: [] })
const qt = reactive({ range: [] })
const qv = reactive({ range: [] })

// 审核
const showReviewDialog = ref(false)
const reviewLoading = ref(false)
const reviewTarget = ref({ type: '', id: null })
const reviewForm = ref({ status: '', opinion: '' })

// 详情
const showActivityDetail = ref(false)
const currentActivity = ref(null)
const activityAttachments = ref([])

// 编辑与保存loading
const saving = reactive({ activity: false, study: false, volunteer: false })

// 组织生活编辑表单
const showActivityEdit = ref(false)
const activityEditForm = reactive({
  id: undefined,
  activityType: '',
  activitySubject: '',
  location: '',
  hostName: '',
  activityDate: '',
  participantCount: 0,
  absenceNotes: '',
  activityRecord: ''
})

// 理论学习详情/编辑
const showStudyDetail = ref(false)
const currentStudy = ref(null)
const showStudyEdit = ref(false)
const studyEditForm = reactive({ id: undefined, studyTopic: '', studyForm: '集中学习', studyDate: '', studyHours: 0, notes: '' })

// 志愿服务详情/编辑
const showVolunteerDetail = ref(false)
const currentVolunteer = ref(null)
const showVolunteerEdit = ref(false)
const volunteerEditForm = reactive({ id: undefined, serviceTitle: '', serviceType: '志愿服务', serviceDate: '', serviceHours: 0, location: '', description: '' })

function d(v){ return String(v || '').substring(0, 10) }
function statusText(s){ return ({ PENDING: '待审核', APPROVED: '已通过', REJECTED: '已驳回' }[s] || '待审核') }
function statusTagType(s){ return ({ PENDING: 'warning', APPROVED: 'success', REJECTED: 'danger' }[s] || 'info') }

function calcStats(list){
  const total = list.length
  let pending=0, approved=0, rejected=0
  for(const i of list){ const s=i.status; if(s==='APPROVED') approved++; else if(s==='REJECTED') rejected++; else pending++; }
  return { total, pending, approved, rejected }
}

async function loadActivities(){
  loading.activities = true
  try{
    const res = await listActivities({ type: qa.type || undefined, startDate: qa.range?.[0], endDate: qa.range?.[1] })
    activities.value = res?.data || res || []
    stats.activities = calcStats(activities.value)
  } finally { loading.activities=false }
}

async function loadStudies(){
  loading.theory = true
  try{
    const res = await getAllStudies({ startDate: qt.range?.[0], endDate: qt.range?.[1] })
    studies.value = res?.data || res || []
    stats.theory = calcStats(studies.value)
  } finally { loading.theory=false }
}

async function loadVolunteers(){
  loading.volunteer = true
  try{
    const res = await getAllVolunteers({ startDate: qv.range?.[0], endDate: qv.range?.[1] })
    volunteers.value = res?.data || res || []
    stats.volunteer = calcStats(volunteers.value)
  } finally { loading.volunteer=false }
}

function refresh(){ if(active.value==='activities') loadActivities(); else if(active.value==='theory') loadStudies(); else loadVolunteers() }

// 操作 - 组织生活
async function viewActivity(row){
  const res = await getActivity(row.id)
  currentActivity.value = res?.activity || res
  activityAttachments.value = res?.attachments || []
  showActivityDetail.value = true
}
function editActivity(row){
  Object.assign(activityEditForm, {
    id: row.id,
    activityType: row.activityType,
    activitySubject: row.activitySubject,
    location: row.location,
    hostName: row.hostName,
    activityDate: d(row.activityDate),
    participantCount: row.participantCount || 0,
    absenceNotes: row.absenceNotes || '',
    activityRecord: row.activityRecord || ''
  })
  showActivityEdit.value = true
}
async function submitActivityEdit(){
  if(!activityEditForm.activityType || !activityEditForm.activitySubject || !activityEditForm.activityDate){
    ElMessage.warning('请填写类型、主题与日期'); return
  }
  saving.activity = true
  try{
    const payload = {
      activity_type: activityEditForm.activityType,
      activity_subject: activityEditForm.activitySubject,
      location: activityEditForm.location,
      host_name: activityEditForm.hostName,
      activity_date: activityEditForm.activityDate,
      participant_count: activityEditForm.participantCount,
      absence_notes: activityEditForm.absenceNotes,
      activity_record: activityEditForm.activityRecord
    }
    await updateActivity(activityEditForm.id, payload)
    ElMessage.success('已保存')
    showActivityEdit.value = false
    await loadActivities()
  } catch(e){ ElMessage.error(e?.response?.data?.message || e?.message || '保存失败') } finally { saving.activity = false }
}
async function removeActivity(row){ await ElMessageBox.confirm('确定删除该记录？','提示',{type:'warning'}); await deleteActivity(row.id); ElMessage.success('已删除'); await loadActivities() }

// 操作 - 理论学习
function viewStudy(row){ currentStudy.value = row; showStudyDetail.value = true }
function editStudy(row){
  Object.assign(studyEditForm, {
    id: row.id,
    studyTopic: row.studyTopic,
    studyForm: row.studyForm,
    studyDate: d(row.studyDate),
    studyHours: row.studyHours || 0,
    notes: row.notes || ''
  })
  showStudyEdit.value = true
}
async function submitStudyEdit(){
  if(!studyEditForm.studyTopic || !studyEditForm.studyDate){ ElMessage.warning('请填写学习主题与日期'); return }
  saving.study = true
  try{
    const payload = {
      study_topic: studyEditForm.studyTopic,
      study_form: studyEditForm.studyForm,
      study_date: studyEditForm.studyDate,
      study_hours: studyEditForm.studyHours,
      notes: studyEditForm.notes
    }
    await updateStudy(studyEditForm.id, payload)
    ElMessage.success('已保存')
    showStudyEdit.value = false
    await loadStudies()
  } catch(e){ ElMessage.error(e?.response?.data?.message || e?.message || '保存失败') } finally { saving.study = false }
}
async function removeStudy(row){ await ElMessageBox.confirm('确定删除该记录？','提示',{type:'warning'}); await deleteStudy(row.id); ElMessage.success('已删除'); await loadStudies() }

// 操作 - 志愿服务
function viewVolunteer(row){ currentVolunteer.value = row; showVolunteerDetail.value = true }
function editVolunteer(row){
  Object.assign(volunteerEditForm, {
    id: row.id,
    serviceTitle: row.serviceTitle,
    serviceType: row.serviceType || '志愿服务',
    serviceDate: d(row.serviceDate),
    serviceHours: row.serviceHours || 0,
    location: row.location || '',
    description: row.description || ''
  })
  showVolunteerEdit.value = true
}
async function submitVolunteerEdit(){
  if(!volunteerEditForm.serviceTitle || !volunteerEditForm.serviceDate){ ElMessage.warning('请填写活动名称与日期'); return }
  saving.volunteer = true
  try{
    const payload = {
      service_title: volunteerEditForm.serviceTitle,
      service_type: volunteerEditForm.serviceType,
      service_date: volunteerEditForm.serviceDate,
      service_hours: volunteerEditForm.serviceHours,
      location: volunteerEditForm.location,
      description: volunteerEditForm.description
    }
    await updateVolunteer(volunteerEditForm.id, payload)
    ElMessage.success('已保存')
    showVolunteerEdit.value = false
    await loadVolunteers()
  } catch(e){ ElMessage.error(e?.response?.data?.message || e?.message || '保存失败') } finally { saving.volunteer = false }
}
async function removeVolunteer(row){ await ElMessageBox.confirm('确定删除该记录？','提示',{type:'warning'}); await deleteVolunteer(row.id); ElMessage.success('已删除'); await loadVolunteers() }

function openReview(type, row){ reviewTarget.value = { type, id: row.id }; reviewForm.value = { status: '', opinion: '' }; showReviewDialog.value = true }
async function submitReview(){
  if(!reviewForm.value.status){ ElMessage.warning('请选择审核结果'); return }
  reviewLoading.value = true
  try{
    if(reviewTarget.value.type==='activity') await reviewActivity(reviewTarget.value.id, { status: reviewForm.value.status, opinion: reviewForm.value.opinion }), await loadActivities()
    else if(reviewTarget.value.type==='study') await reviewStudy(reviewTarget.value.id, { status: reviewForm.value.status, opinion: reviewForm.value.opinion }), await loadStudies()
    else await reviewVolunteer(reviewTarget.value.id, { status: reviewForm.value.status, opinion: reviewForm.value.opinion }), await loadVolunteers()
    ElMessage.success('审核完成')
    showReviewDialog.value = false
  } catch(e){ ElMessage.error(e?.response?.data?.message || e?.message || '审核失败') } finally { reviewLoading.value=false }
}

onMounted(async ()=>{ await Promise.all([loadActivities(), loadStudies(), loadVolunteers()]) })
</script>

<style scoped>
.party-overview { max-width: 1400px; }
.page-header { display:flex; justify-content:space-between; align-items:center; margin-bottom:16px; }
.filters { display:flex; align-items:center; flex-wrap:wrap; gap:12px; }
.stats-row { margin: 12px 0; }
.stat { text-align:center; }
.num { font-size: 24px; font-weight:600; }
.num.success { color:#67c23a; }
.num.danger { color:#f56c6c; }
.num.info { color:#909399; }
</style>


